{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "breeding-filter",
   "metadata": {},
   "source": [
    "https://leetcode.com/problems/most-common-word\n",
    "\n",
    "\n",
    "Runtime: 40 ms, faster than 36.43% of Python3 online submissions for Most Common Word.\n",
    "Memory Usage: 14.4 MB, less than 20.43% of Python3 online submissions for Most Common Word.\n",
    "\n",
    "\n",
    "```python\n",
    "import re \n",
    "\n",
    "class Solution:\n",
    "    def mostCommonWord(self, paragraph: str, banned: List[str]) -> str:\n",
    "        #5:43\n",
    "        def word_only(word):\n",
    "            n = \"\"\n",
    "            for c in word:\n",
    "                if c.isalpha():\n",
    "                    n += c.lower()\n",
    "            return n\n",
    "        \n",
    "        words = re.split(r\"[ ,]\", paragraph)\n",
    "        \n",
    "        d = dict()\n",
    "        for word in words:\n",
    "            word = word_only(word)\n",
    "            if len(word):\n",
    "                if word in d:\n",
    "                    d[word] += 1\n",
    "                else:\n",
    "                    d[word] = 1\n",
    "        items = {k: v for k, v in sorted(d.items(), key=lambda item: item[1])}\n",
    "        print(items)\n",
    "        for word in reversed(items.keys()):\n",
    "            if word not in banned:\n",
    "                return word\n",
    "        #6:01\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "informative-location",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
